﻿using Dapper;
using MediatR;
using MySql.Data.MySqlClient;
using SCM.API.Read.Application.Command.Purchase;
using SCM.Domain;
using SCM.ErrorCode;
using SCM.Infrastructure.Interface;
using System.Text;
using Warehouse.Domian.Model;

namespace SCM.API.Read.Application.Handler.Purchase
{
    public class GetBatchHandler : IRequestHandler<GetBatchCommand, APIResult<Stocking>>
    {
        IDatabaseContext db;

        public GetBatchHandler(IDatabaseContext db)
        {
            this.db = db;
        }

        public async Task<APIResult<Stocking>> Handle(GetBatchCommand request, CancellationToken cancellationToken)
        {
            var result = new APIPaging<Stocking>();

            var sqlBuilder = new StringBuilder();

            sqlBuilder.Append(@"SELECT 
                                        ProductId,
                                        Bacth
                                FROM Stocking WHERE IsDeleted=0 ");

            var parameters = new DynamicParameters();

            

           

            var data = await db.DapperConnection.QueryAsync<Stocking>(sqlBuilder.ToString(), parameters);

            result.Msg = "显示成功";
            result.Code = APIEnum.Success;
            result.Datas = data.ToList();

            return result;
        }
    }
}
